﻿Public Class frmMResultadoexamenws
    Public arrConsulta(2) As String
    Private arrCampos() As String = {"resultadoexamen_id", "resultadoexamen_nombre", "resultadoexamen_idcrc"}

    Private Sub frmMResultadoexamenws_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        mdiPrincipal.tsmiResultadoexamenws.Enabled = True
    End Sub

    Private Sub frmMResultadoexamenws_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        refreshList()
    End Sub

    Private Sub tsbNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbNuevo.Click
        Me.tsbNuevo.Enabled = False
        Me.renderForm("Nuevo - Resultado Examen", 1)
    End Sub

    Private Sub tsbConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbConsultar.Click
        Me.tsbConsultar.Enabled = False
        Me.renderForm("Consultar - Resultado Examen", 2)
    End Sub

    Private Sub tsbEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbEditar.Click
        Dim strId As String = Me.dgvResultadoexamen.Rows(Me.dgvResultadoexamen.CurrentRow.Index).Cells(0).Value.ToString()

        If (strId <> "") Then
            Me.tsbEditar.Enabled = False
            renderForm("Editar - Resultado Examen", 3)
        Else
            MsgBox("Debe seleccionar un registro", MsgBoxStyle.Information, "Resultado Examen")
        End If
    End Sub

    Private Sub tsbBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbBorrar.Click
        Dim objResult = MsgBox("Esta seguro que desea borrar el registro seleccionado?", MsgBoxStyle.YesNo, "Borrar - Resultado Examen")

        If (objResult = DialogResult.Yes) Then
            Dim strId As String = Me.dgvResultadoexamen.Rows(Me.dgvResultadoexamen.CurrentRow.Index).Cells(0).Value.ToString

            mdlConexion.blnOnDB = True
            mdlCRUD.delRecord("resultadoexamen", "resultadoexamen_id = '" & strId & "'")
            mdlConexion.blnOnDB = False

            If (mdlCRUD.blnFlag = True) Then
                Me.refreshList()
            End If
        End If
    End Sub

    Private Sub tsbRecargar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbRecargar.Click
        arrConsulta(0) = ""
        arrConsulta(1) = ""
        arrConsulta(2) = ""
        Me.refreshList()
    End Sub

    Private Sub renderForm(ByVal strTitle As String, ByVal intMode As Integer)
        Dim frmResultadoexamen As New frmResultadoexamenws

        frmResultadoexamen.MdiParent = mdiPrincipal
        frmResultadoexamen.frmParent = Me

        frmResultadoexamen.modeForm = intMode
        frmResultadoexamen.Text = strTitle
        frmResultadoexamen.Show()

    End Sub

    Public Sub refreshList()
        Dim dstRecord As New DataSet
        Dim strCondicion As String = ""
        dstRecord.Tables.Add("Resultadoexamen")

        For i As Integer = 0 To 2
            If (Me.arrConsulta(i) <> "") Then
                strCondicion &= IIf(strCondicion <> "", " AND ", "") & IIf(i <> 1, Me.arrCampos(i) & " = '" & LCase(Me.arrConsulta(i)) & "'", "LOWER(" & Me.arrCampos(i) & "::text) LIKE '%" & LCase(Me.arrConsulta(i)) & "%'")
            End If
        Next

        mdlConexion.blnOnDB = True
        mdlCRUD.loadRecord(dstRecord, "Resultadoexamen", "resultadoexamen", strCondicion, "resultadoexamen_id")
        mdlConexion.blnOnDB = False

        Me.dgvResultadoexamen.DataSource = dstRecord.Tables("Resultadoexamen")

        Me.dgvResultadoexamen.Columns(0).HeaderText = "Codigo"
        Me.dgvResultadoexamen.Columns(1).HeaderText = "Resultado Examen"
        Me.dgvResultadoexamen.Columns(2).HeaderText = "ID Integración"
        Me.dgvResultadoexamen.Columns(0).Width = 60
        Me.dgvResultadoexamen.Columns(1).Width = 260
        Me.dgvResultadoexamen.Columns(2).Width = 100
    End Sub
End Class